//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.mopub.nativeads;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;

import com.cs.bd.ad.params.AdSdkParamsBuilder;
import com.cs.bd.ad.self.VirtualIdParseHelper;
import com.cs.bd.mopub.MopobViewGroupWarp;
import com.miui.zeus.mimo.sdk.ad.IAdWorker;

public class NativeAd {

    @Nullable
    private NativeAd.MoPubNativeEventListener mMoPubNativeEventListener;

    private boolean mIsDestroyed;

    private ViewGroup mAdView;

    private IAdWorker myAdWorker;

    private AdSdkParamsBuilder adSdkParams;

    private boolean isExternalAds;

    public NativeAd(ViewGroup view, AdSdkParamsBuilder adSdkParams) {
        this.mAdView = view;
        this.adSdkParams = adSdkParams;
        VirtualIdParseHelper.isExternalAds(view.getContext(), adSdkParams.mVirtualModuleId);
    }

    public void setMoPubNativeEventListener(@Nullable NativeAd.MoPubNativeEventListener moPubNativeEventListener) {
        this.mMoPubNativeEventListener = moPubNativeEventListener;
    }

    @NonNull
    public View createAdView(@NonNull Context context, @Nullable ViewGroup parent) {
        try {
            MopobViewGroupWarp mopobViewGroupWarp = new MopobViewGroupWarp(context);
            View view = adSdkParams.mMoPubAdConfig.mMoPubNativeConfig.mMoPubAdRenderer.createAdView(context, parent);
            mopobViewGroupWarp.addView(view);
            mopobViewGroupWarp.addAdView(mAdView);
            return mopobViewGroupWarp;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mAdView;
    }

    public void renderAdView(View view) {
        if (MopobViewGroupWarp.class.isInstance(view)) {
            try {
                MopobViewGroupWarp mopobViewGroupWarp = (MopobViewGroupWarp) view;
                mopobViewGroupWarp.renderAdView(adSdkParams.mMoPubAdConfig.mMoPubNativeConfig.mMoPubAdRenderer.getViewHolder(), isExternalAds);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public void prepare(@NonNull View view) {
    }

    public void clear(@NonNull View view) {
    }

    public void destroy() {
        if (!this.mIsDestroyed) {
            try {
                myAdWorker.recycle();
            } catch (Exception e) {
                e.printStackTrace();
            }
            this.mIsDestroyed = true;
        }
    }

    public void setIAdWorker(IAdWorker myAdWorker) {
        this.myAdWorker = myAdWorker;
    }

    public void onImpression() {
        if (mMoPubNativeEventListener != null) {
            mMoPubNativeEventListener.onImpression(mAdView);
        }
    }

    public void onClick() {
        if (mMoPubNativeEventListener != null) {
            mMoPubNativeEventListener.onClick(mAdView);
        }
    }

    public interface MoPubNativeEventListener {
        void onImpression(View var1);

        void onClick(View var1);
    }
}
